package com.ruoyi.bus.wechat;

import java.util.Date;

/**
 * @Description 微信accesstoken
 * @Author caiyanshan
 * @Date 2020/10/16 10:43
 * @Param
 * @Return
 */
public class AccessToken {
  private String access_token;
  private Long expires_in;//过期时间
  private Date startTime;//调用时间
  
  public boolean isExpire() {
    if(getDatePoor(new Date(), startTime) > (expires_in - 200)){//防止传递数据不准确，导致过期，所以减点200
        return true;
    }
    return false;
  }
  
  public Long getDatePoor(Date endDate, Date nowDate)
  {
    long nd = 1000 * 24 * 60 * 60;
    long nh = 1000 * 60 * 60;
    long nm = 1000 * 60;
    long ns = 1000;
    // 获得两个时间的毫秒时间差异
    long diff = endDate.getTime() - nowDate.getTime();
    // 计算差多少秒//输出结果
    long sec = diff % nd % nh % nm / ns;
    return sec;
  }
  
  public Date getStartTime() {
    return startTime;
  }
  
  public void setStartTime(Date startTime) {
    this.startTime = startTime;
  }
  
  public String getToken() {
    return access_token;
  }
  
  public void setToken(String access_token) {
    this.access_token = access_token;
  }
  
  public Long getExpiresTime() {
    return expires_in;
  }
  
  public void setExpiresTime(Long expiresTime) {
    this.expires_in = expiresTime;
  }
}
